package com.gray.common;

import java.util.List;

public class Page {
	private int everyPage; // 每页显示的条数
	private int totalCount; // 总共需要显示的条数
	private int totalPage; // 总共需要显示的页数
	private int currentPage; // 当前的页数
	private boolean hasPrePage; // 是否有上一页
	private boolean hasNextPage; // 是否有下一页
	private int dbFromIndex ;

	
	public Page(){
		
	}
	/*
	 * 初始化 获得数据源   （当前页数  每页的数据量)前端传来
	 */
	
	public Page(int totalCount,int currentPage , int everyPage){
		if(totalCount ==0){
			return ;
		}
		
		this.totalCount = totalCount;
		this.everyPage = everyPage;
		this.totalPage = this.totalCount % this.everyPage ==0 ? this.totalCount /this.everyPage :this.totalCount/this.everyPage+1;
		this.currentPage = this.totalPage < currentPage ? this.totalPage : currentPage;
		int startIndex = this.everyPage * (this.currentPage-1);
		int endIndex = this.everyPage * this.currentPage > this.totalCount ? totalCount :this.everyPage * this.currentPage;
		this.hasNextPage = this.currentPage * this.everyPage  < this.totalCount;
		this.hasPrePage = this.currentPage >1;
		this.dbFromIndex = this.everyPage * (this.currentPage-1);
	}	
	
	public int getDbFromIndex() {
		return dbFromIndex;
	}

	public void setDbFromIndex(int dbFromIndex) {
		this.dbFromIndex = dbFromIndex;
	}

	public int getEveryPage() {
		return this.everyPage;
	}

	public void setEveryPage(int everyPage) {
		this.everyPage = everyPage;
	}

	public int getTotalCount() {
		return this.totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getTotalPage() {
		return this.totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public boolean isHasPrePage() {
		return this.hasPrePage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public void setHasPrePage(boolean hasPrePage) {
		this.hasPrePage = hasPrePage;
	}

	public boolean isHasNextPage() {
		return this.hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

}
